package com.guigu.www.erp.luolujin.controller;

import com.guigu.www.erp.dehao.pojo.Menu;
import com.guigu.www.erp.dehao.pojo.RoleMenu;
import com.guigu.www.erp.luolujin.service.LljMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/menu")
public class LljMenuServlet {
    @Autowired
    private LljMenuService service;

    @GetMapping("/find")
    public List<Menu> findMune(){
        return service.findMenu();
    }

    @GetMapping("{rname}")
    public List<RoleMenu> findRoleMenu(@PathVariable int rname){
        return service.findByRoleId(rname);
    }
    @DeleteMapping("{rname}")
    public Integer delRoleMenu(@PathVariable Integer rname){
        service.deleteByMenuId(rname);
        return 0;
    }
    @PostMapping("/add")
    public int insertRoleMenu(int roleId,int[] arr){
        for (int arra:arr) {
            RoleMenu roleMenu = new RoleMenu(null, roleId, arra);
            service.insertSelective(roleMenu);
        }
        return 1;
    }
}
